package service

import (
	"gitee.com/apinktara/cart/domain/model"
	"gitee.com/apinktara/cart/domain/repository"
)

type ICartDataService interface {
	AddCart(product *model.Cart) (int64, error)
	DeleteCart(int64) error
	UpdateCart(*model.Cart) error
	FindCartByID(int64) (*model.Cart, error)
	FindAllCart(int64) ([]model.Cart, error)
	CleanCart(int64) error
	IncrNum(int64, int64) error
	DecrNum(int64, int64) error
}

func NewCartDataService(productRepository repository.ICartRepository) ICartDataService {
	return &CartDataService{CartRspository: productRepository}
}

type CartDataService struct {
	CartRspository repository.ICartRepository
}

func (u *CartDataService) AddCart(product *model.Cart) (int64, error) {
	return u.CartRspository.CreateCart(product)
}

func (u *CartDataService) DeleteCart(productID int64) error {
	return u.CartRspository.DeleteCartByID(productID)
}

func (u *CartDataService) UpdateCart(product *model.Cart) error {
	return u.CartRspository.UpdateCart(product)
}

func (u *CartDataService) FindCartByID(productID int64) (*model.Cart, error) {
	return u.CartRspository.FindCartByID(productID)
}
func (u *CartDataService) FindAllCart(userID int64) ([]model.Cart, error) {
	return u.CartRspository.FindAll(userID)
}

func (u *CartDataService) CleanCart(userID int64) error {
	return u.CartRspository.CleanCart(userID)
}

func (u CartDataService) DecrNum(cartID int64, num int64) error {
	return u.CartRspository.DecrNum(cartID, num)
}

func (u CartDataService) IncrNum(cartID int64, num int64) error {
	return u.CartRspository.IncrNum(cartID, num)
}
